'''
$LastChangedBy: csgillespie $
$LastChangedDate: 2007-06-06 11:08:06 +0000 (Wed, 06 Jun 2007) $
Tests the configuration file class
'''
import unittest
import ConfigParser
import os, sys
DIR = '/data/ncsg3/svn/pythonR/BasisTools/trunk/'
sys.path.insert(0, DIR )
from pysbml.GlobalVariables import ConfigFile
from pysbml.GlobalVariables.ErrorClasses import BasisConfigError
#from pysbml import ErrorClasses


class TestConfigFile(unittest.TestCase):
	'''Tests the configuration File'''
	def setUp(self):
		'''Make a list of the SBML files available'''
		file = os.path.expanduser('~/.pysbml')
		try:
			open(file)
			os.remove(file)
		except IOError:
			pass
	
	def testCreateConfig(self):                                        
		'''Test createing config file'''
		ConfigFile.createConfigFile()
		file = os.path.expanduser('~/.pysbml')
		fp = open(file)
		config = ConfigParser.SafeConfigParser()
		config.readfp(open(file))
		self.assertEqual(config.has_section('Basis WS'), True)
		for value in ('username', 'password', 'model_urn', \
			'simulation_group_urn'):
			self.assertEqual(config.get('Basis WS', value), 'None')
	
	def testaddToConfigFile(self):                                        
		'''Test the visualisation of models'''
		ConfigFile.createConfigFile()
		config_dict = {'username':'colin', 'password':'colin', 'model_urn':None,
			'simulation_group_urn':None, 's_id':None}
		ConfigFile.addToConfigFile(config_dict )
		
		for key in config_dict.keys():
			new_config_dict = ConfigFile.getConfigFile()
			self.assertEqual(new_config_dict[key], config_dict[key])
			
		self.assertRaises(BasisConfigError, ConfigFile.addToConfigFile, {'X':'X'})
if __name__ == '__main__':
    unittest.main()
